package com.local.videoplayer.dialogs;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import com.local.videoplayer.R;

/**
 * Created by ccx on 16/9/13.
 * 全局基类Dialog
 */
public abstract class BaseDialogFragment extends DialogFragment implements View.OnClickListener {

    @Override
    public void onClick(View v) {

    }

    protected boolean canCanceledOnTouchOutside() {
        return true;
    }

    public abstract int getLayoutId();

    public abstract void initView(View view);

    public abstract void initLayoutParams(WindowManager.LayoutParams wlp);

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        getDialog().setCanceledOnTouchOutside(canCanceledOnTouchOutside());
        setCancelable(canCanceledOnTouchOutside());
        View view = inflater.inflate(getLayoutId(), container, false);
        initLayoutParams(getDialog().getWindow().getAttributes());
        initView(view);
        return view;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_FRAME, getTheme());
    }

    public int getTheme() {
        return R.style.dialog_fragment;
    }
    public void showDialog(FragmentManager manager) {
        if (!isAdded()) {
            show(manager, "BaseDialogFragment" + Math.random());
        }
    }
}
